package com.maxd.modules.selfshop.prize.service.impl;

import com.maxd.error.Result;
import com.maxd.error.ResultUtil;
import com.maxd.modules.selfshop.prize.entity.SelfPrizeRule;
import com.maxd.modules.selfshop.prize.respository.SelfPrizeRuleJpaRepository;
import com.maxd.modules.selfshop.prize.service.SelfPrizeRuleService;
import com.maxd.utils.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SelfPrizeRuleServiceImpl implements SelfPrizeRuleService {
    @Autowired
    private SelfPrizeRuleJpaRepository jpaRepository;

    @Override
    public Result findAll() {
        return ResultUtil.success(jpaRepository.findAll());
    }

    @Override
    public Result userList() {
        return ResultUtil.success(jpaRepository.findAllByStatus(1));
    }

    @Override
    public Result saveBody(SelfPrizeRule entity) {
        entity.setCreateTime(DateUtil.createTime());
        return ResultUtil.success(jpaRepository.save(entity));
    }

    @Override
    public Result updateBody(SelfPrizeRule entity) {
        return ResultUtil.success(jpaRepository.save(entity));
    }

    @Override
    public Result findOne(Long id) {
        return ResultUtil.success(jpaRepository.findById(id).orElse(null));
    }

    @Override
    public Result delete(Long id) {
        jpaRepository.deleteById(id);
        return ResultUtil.success();
    }

}
